package net.lab1024.sa.admin.common;

import java.util.HashMap;
import java.util.Map;

public class EnumConverter {
    // 学院映射
    public static final Map<String, String> COLLEGE_MAP = new HashMap<>();
    // 班级映射
    public static final Map<String, String> CLASS_MAP = new HashMap<>();
    // 职务映射
    public static final Map<String, Integer> POSITION_MAP = new HashMap<>();
    // 角色映射
    public static final Map<String, Integer> ROLE_MAP = new HashMap<>();
    // 状态映射
    public static final Map<String, Integer> STATUS_MAP = new HashMap<>();
    // 状态映射
    public static final Map<String, Integer> YN_MAP = new HashMap<>();
    // 性别映射
    public static final Map<String, Integer> SEX_MAP = new HashMap<>();
    // 数据库映射
    public static final Map<String, String> DATABASE_MAP = new HashMap<>();
    // 模型映射
    public static final Map<String, String> MODEL_MAP = new HashMap<>();

    public static final Integer superAdministratorId = 2;
    public static final Integer generalUserRoleCode = 1;
    public static final Integer defaultStatus = 1;
    public static final Integer defaultYn = 1;

    static {
        COLLEGE_MAP.put("化学院", "chemistry");
        COLLEGE_MAP.put("医学院", "medical");

        CLASS_MAP.put("一班", "Class1");
        CLASS_MAP.put("二班", "Class2");
        CLASS_MAP.put("三班", "Class3");
        CLASS_MAP.put("四班", "Class4");
        CLASS_MAP.put("五班", "Class5");

        POSITION_MAP.put("学生", 0);
        POSITION_MAP.put("老师", 1);
        POSITION_MAP.put("助教", 2);

        ROLE_MAP.put("管理员", 0);
        ROLE_MAP.put("普通用户", 1);
        ROLE_MAP.put("超级管理员", 2);

        STATUS_MAP.put("禁用", 0);
        STATUS_MAP.put("正常", 1);

        YN_MAP.put("已删除", 0);
        YN_MAP.put("未删除", 1);

        SEX_MAP.put("男", 1);
        SEX_MAP.put("女", 2);

        DATABASE_MAP.put("emol_under_0", "emol_under_0");
        DATABASE_MAP.put("emol_under_1", "emol_under_1");
        DATABASE_MAP.put("emol_under_2", "emol_under_2");
        DATABASE_MAP.put("emol_under_3", "emol_under_3");
        DATABASE_MAP.put("emol_under_4", "emol_under_4");
        DATABASE_MAP.put("emol_under_5", "emol_under_5");

        MODEL_MAP.put("simpretro", "simpretro");
    }


    public static Integer convertSexNameToCode(String name) {
        for (Map.Entry<String, Integer> entry : SEX_MAP.entrySet()) {
            if (entry.getKey().equals(name)) {
                return entry.getValue();
            }
        }
        return -1;
    }


    public static String convertSexCodeToName(Integer code) {
        for (Map.Entry<String, Integer> entry : SEX_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }

    public static String convertClassNameToCode(String name) {
        for (Map.Entry<String, String> entry : CLASS_MAP.entrySet()) {
            if (entry.getKey().equals(name)) {
                return entry.getValue();
            }
        }
        return "";
    }

    public static String convertClassCodeToName(String code) {
        for (Map.Entry<String, String> entry : CLASS_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }

    public static String convertCollegeNameToCode(String name) {
        return COLLEGE_MAP.getOrDefault(name, "");
    }

    public static String convertCollegeCodeToName(String code) {
        for (Map.Entry<String, String> entry : COLLEGE_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }


    public static Integer convertPositionNameToCode(String name) {
        return POSITION_MAP.getOrDefault(name, 0);
    }

    public static String convertPositionCodeToName(Integer code) {
        for (Map.Entry<String, Integer> entry : POSITION_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }


    public static Integer convertRoleNameToCode(String name) {
        return ROLE_MAP.getOrDefault(name, 1);
    }

    public static String convertRoleCodeToName(Integer code) {
        for (Map.Entry<String, Integer> entry : ROLE_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }


    public static Integer convertStatusNameToCode(String name) {
        return STATUS_MAP.getOrDefault(name, 1);
    }

    public static String convertStatusCodeToName(Integer code) {
        for (Map.Entry<String, Integer> entry : STATUS_MAP.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "";
    }

}